<?php
/**
 * Created by PhpStorm.
 * User: krystal
 * Date: 2019/4/23
 * Time: 10:20
 */

namespace app\common\model;


use XznsTools\cache\CacheManage;

class ZlAstrInfo extends BaseCache
{
    protected $table = 'wechat_backup_07_18_14_43_00.zl_astr_info';
    protected $cacheModel = 'astr_info';

    /**
     * 获取用户认证信息
     * @param $uid
     * @param $field
     * @return array|bool|string
     * @throws \Exception
     */
    public function UserAstrInfo($uid, $field = '')
    {
        $field = is_string($field) ? $field : implode(',', $field);
        $data = CacheManage::getInstance()->setCacheConfig($this->cacheModel, $uid)
            ->getCache($field, 'details');
        if ($data === false)
        {
            $where = ['uid' => $uid];

            $field = 'id,uid,name,nickname,telphone,id_number,area_ids,left_pic,right_pic,certificate_pic,create_time,update_time';
            try
            {
                $data = $this->where($where)->column($field, 'uid');
                CacheManage::getInstance()->setCacheConfig($this->cacheModel, $uid)
                    ->setCache($data, 'details', false);
            }
            catch (\Exception $e)
            {
                $data = [];
            }
        }
        return $data;
    }

    /**
     * 数据库批量获取用户认证信息
     * @param $ids
     * @param $type
     * @param $sortType
     * @return array|void
     */
    public function getInfoByIdsInData($ids, $type, $sortType)
    {
        $where = ['uid' => ['in', $ids]];
        try
        {
            $data = $this->where($where)->column('id,uid,name,nickname,telphone,id_number,area_ids,left_pic,right_pic,certificate_pic,create_time,update_time', 'uid');
        }
        catch (\Exception $e)
        {
            $data = [];
        }

        return $data;
    }

}